import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-19
 * Time: 16:06
 */
public class Demo42 {
    public static void main(String[] args) {
        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(1000);
        Thread producer = new Thread(() -> {
            int n = 0;
            while(true) {
                try {
                    queue.put(n);
                    System.out.println("生产者生产：" + n);
//                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                n++;
            }
        },"producer");
        Thread consumer = new Thread(() -> {
            while(true) {
                try {
                    int value = queue.take();
                    System.out.println("消费者消费：" + value);
//                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"consumer");
        producer.start();
        consumer.start();
    }
}
